package top.milkbox.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.milkbox.info.AllVariable;
import top.milkbox.info.BaiduTranslationInfo.TranslationSuccessResult;
import top.milkbox.info.R;
import top.milkbox.service.BaiduTranslationService;
import top.milkbox.service.VariableNamerService;

@RestController
@RequestMapping("/vnc")
public class VariableNamerController {

    @Autowired
    private VariableNamerService variableNamerService;

    @Autowired
    private BaiduTranslationService baiduTranslationService;


    /**
     * 将中文翻译为英文并获取这个英文的所有变量名方式
     *
     * @param source 原文
     * @return R
     */
    @GetMapping("/getAll")
    public R getAllName(String source) {
        R r = new R();
        TranslationSuccessResult successResult = baiduTranslationService.translate(source);
        if (successResult == null) {
            r.setFlag(false);
            r.setMessage("翻译出错");
            return r;
        }
        String translationResult = successResult.getTrans_result().get(0).getDst();

        // 获取所有的变量名情况
        AllVariable allVariable = variableNamerService.getAllVariable(translationResult);

        r.setFlag(true);
        r.setData(allVariable);
        r.setMessage("操作成功");
        return r;
    }

}
